import { ApiProperty } from "@nestjs/swagger";
import { IsArray, IsEnum, IsNotEmpty, IsNumber, IsOptional, IsString } from "class-validator";
import { Msgs } from "@/common/type/msg";
import { BooleanType, FeeInOutType } from "@/common/type/enum";


export class ProtocolDto {
    @IsString({
        message: '协议代码错误'
    })
    @IsNotEmpty({
        message: '协议代码不能为空'
    })
    @ApiProperty({ description: '协议代码'})
    protocol_cod: string;

    @IsString({
        message: '协议名称错误'
    })
    @IsNotEmpty({
        message: '协议名称不能为空'
    })
    @ApiProperty({ description: '协议名称'})
    protocol_nam: string;

    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;

}

export class FeeEleDto {

    @IsString({
        message: '费用元素错误'
    })
    @IsNotEmpty({
        message: '费用元素不能为空'
    })
    @ApiProperty({ description: '费用元素代码'})
    fee_ele: string;

    @IsString({
        message: '费用元素英文错误'
    })
    @IsNotEmpty({
        message: '费用元素英文不能为空'
    })
    @ApiProperty({ description: '费用元素英文'})
    e_fld_nam: string;

    @IsString({
        message: '费用元素中文错误'
    })
    @IsNotEmpty({
        message: '费用元素中文不能为空'
    })
    @ApiProperty({ description: '费用元素中文'})
    c_fld_nam: string;

    @IsString({
        message: '更新sql错误'
    })
    @IsOptional()
    @ApiProperty({ description: '更新sql'})
    from_table: string;
    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;
}

export class FeeEleLovDto {
    @IsString({
        message: '费用元素错误'
    })
    @IsNotEmpty({
        message: '费用元素中文不能为空'
    })
    @ApiProperty({ description: '费用元素中文'})
    fee_ele: string;

    @IsString({
        message: '费用元素值错误'
    })
    @IsNotEmpty({
        message: '费用元素值不能为空'
    })
    @ApiProperty({ description: '费用元素值'})
    fld_cod: string;

    @IsString({
        message: '英文值错误'
    })
    @IsNotEmpty({
        message: '英文值不能为空'
    })
    @ApiProperty({ description: '英文值'})
    e_fld_nam: string;

    @IsString({
        message: '中文值错误'
    })
    @IsNotEmpty({
        message: '中文值不能为空'
    })
    @ApiProperty({ description: '中文值'})
    c_fld_nam: string;

    @IsNumber({},  {
        message: '排序值错误'
    })
    @IsOptional()
    @ApiProperty({ description: '排序值'})
    lov_order: number;
    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;
}

export class FeeModDto {
    @IsString({
        message: '计费模式错误'
    })
    @IsNotEmpty({
        message: '计费模式不能为空'
    })
    @ApiProperty({ description: '计费模式代码'})
    fee_mod_cod: string;

    @IsString({
        message: '计费模式名称错误'
    })
    @IsNotEmpty({
        message: '计费模式名称不能为空'
    })
    @ApiProperty({ description: '计费模式名称'})
    fee_mod_nam: string;
    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;
}

export class FeeModEleDto {
    @IsString({
        message: '计费模式错误'
    })
    @IsNotEmpty({
        message: '计费模式不能为空'
    })
    @ApiProperty({ description: '计费模式代码'})
    fee_mod_cod: string;

    @IsString({
        message: '计费模式要素错误'
    })
    @IsNotEmpty({
        message: '计费模式要素不能为空'
    })
    @ApiProperty({ description: '计费模式要素名称'})
    fee_ele: string;

    @IsNumber({}, {
        message: '排序错误'   
    })
    @ApiProperty({ description: '排序号'})
    fee_ele_seq: number;
    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;

}
export class FeeCodDto {

    /* @IsString({
        message: 'fee_cod错误'
    })
    @IsNotEmpty({
        message: 'fee_cod不能为空'
    })
    fee_cod: string; */

    @IsString({
        message: Msgs.FeeCodNamInvalid
    })
    @IsNotEmpty({
        message: Msgs.FeeCodNamEmpty
    })
    @ApiProperty({ description: '费用名称'})
    fee_nam: string;

    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark: string;

}
export class FeeTypDto {
    @IsString({
        message: 'fee_typ_cod错误'
    })
    @IsNotEmpty({
        message: 'fee_typ_cod不能为空'
    })
    fee_typ_cod: string;

    @IsString({
        message: 'fee_typ_nam错误'
    })
    @IsNotEmpty({
        message: 'fee_typ_nam不能为空'
    })
    fee_typ_nam: string;

    @IsString()
    @IsOptional()
    remark: string;

}

export class FeeCodModDto {
    @IsString({
        message: Msgs.FeeCodNamInvalid
    })
    @IsNotEmpty({
        message: Msgs.FeeCodNamEmpty
    })
    @ApiProperty({ description: '费目名称'})
    fee_cod: string;

    @IsString({
        message: '模式错误'
    })
    @IsNotEmpty({
        message: '模式不能为空'
    })
    @ApiProperty({ description: '模式名称'})
    fee_mod: string;

    @IsNumber({}, {
        message: '排序参数错误'
    })
    @IsOptional()
    @ApiProperty({ description: '排序'})
    mod_seq: number;
    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;
}


export class CategoryDto {
    @IsString({
        message: Msgs.CategoryInvalid
    })
    @IsNotEmpty({
        message: Msgs.CategoryEmpty
    })
    @ApiProperty({ description: '资金账号名称'})
    cate_item_nam: string;

    @IsString({
        message: Msgs.CategoryCurrencyInvalid
    })
    @IsNotEmpty({
        message: Msgs.CategoryCurrencyEmpty
    })
    @ApiProperty({ description: '货币'})
    currency_cod: string;

    @IsString()
    @IsOptional()
    account: string;

    @IsString()
    @IsOptional()
    bank: string;

    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;
}

export class CurrencyDto {
    @IsString({
        message: Msgs.CurrencyInvalid
    })
    @IsNotEmpty({
        message: Msgs.CurrencyEmpty
    })
    @ApiProperty({ description: '货币代码'})
    currency_cod: string;

    @IsString({
        message: Msgs.CurrencyInvalid
    })
    @IsNotEmpty({
        message: Msgs.CurrencyEmpty
    })
    @ApiProperty({ description: '货币名称'})
    currency_nam: string;

    @IsNumber({}, {
        message: Msgs.CurrencyInvalid
    })
    @IsNotEmpty({
        message: Msgs.CurrencyEmpty
    })
    @ApiProperty({ description: '汇率'})
    rate: number;
    
    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;
}

export class ExchangeRateDto {
    @IsString({
        message: Msgs.CurrencyInvalid
    })
    @IsNotEmpty({
        message: Msgs.CurrencyEmpty
    })
    from_currency: string;

    @IsString({
        message: Msgs.CurrencyInvalid
    })
    @IsNotEmpty({
        message: Msgs.CurrencyEmpty
    })
    to_currency: string;

    @IsNumber({}, {
        message: Msgs.CurrencyInvalid
    })
    @IsNotEmpty({
        message: Msgs.CurrencyEmpty
    })
    rate: number;

    @IsString()
    @IsOptional()
    remark?: string;
}

export class PayDto {
    @IsNotEmpty({
        message: '客户不能为空'
    })
    fee_unit_cod: number;

    @IsNotEmpty({
        message: '金额不能为空'
    })
    amount: number;

    @IsNotEmpty({
        message: '货币不能为空'
    })
    currency_cod: string;

    st_amount: number;
    currency_rate: number;
    fee_nam: string;
    @IsNotEmpty({
        message: '付款时间不能为空'
    })
    fee_tim: Date;

    @IsNotEmpty({
        message: '资金账号不能为空'
    })
    pay_typ: number;
    @IsNotEmpty({
        message: '收付款不能为空'
    })
    fee_in_out: FeeInOutType;
    audit_id: BooleanType;
    audit_finish_id: BooleanType;
    pay_no: string;
    special_id: BooleanType;
    need_audit: BooleanType;
    cfs_cod: number;
    @IsNotEmpty({
        message: '成本中心不能为空'
    })
    fee_owner: number
    @IsNotEmpty({
        message: '费用类型不能为空'
    })
    fee_typ_cod: string
    fee_cod: string;
    fee_bill_no: string;
    auto_audit: string;
    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;
}
export class PrePayDto {
    @IsNotEmpty({
        message: '客户不能为空'
    })
    fee_unit_cod: number;

    @IsNotEmpty({
        message: '金额不能为空'
    })
    amount: number;

    @IsNotEmpty({
        message: '货币不能为空'
    })
    currency_cod: string;

    
    fee_nam: string;

    @IsNotEmpty({
        message: '付款时间不能为空'
    })
    fee_tim: Date;

    @IsNotEmpty({
        message: '资金账号不能为空'
    })
    pay_typ: number;
    @IsNotEmpty({
        message: '收付款不能为空'
    })
    fee_in_out: FeeInOutType;
    @IsNotEmpty({
        message: '成本中心不能为空'
    })
    fee_owner: number
    @IsNotEmpty({
        message: '费用类型不能为空'
    })
    fee_typ_cod: string
    fee_cod: string;
    pay_no: string;
    @IsString()
    @IsOptional()
    remark?: string;
}
export class FeedetDto {
    total_no: string;
    fee_bill_no: string;
    bill_no: string;
    fix_list_id: number;
    @IsNotEmpty({
        message: '客户不能为空'
    })
    fee_unit_cod: number;
    cntr_no: number;
    cntr: string;
    @IsNotEmpty({
        message: '成本中心不能为空'
    })
    fee_owner: number;
    @IsNotEmpty({
        message: '费目类型不能为空'
    })
    fee_typ_cod: string;
    @IsNotEmpty({
        message: '费目不能为空'
    })
    fee_cod: string;
    /* @IsNotEmpty({
        message: '单价不能为空'
    }) */
    fee_value: number;
    st_value: number;
    fee_ton: number;
    @IsNotEmpty({
        message: '金额不能为空'
    })
    amount: number;
    st_amount: number;
    @IsNotEmpty({
        message: '货币不能为空'
    })
    currency_cod: string;
    pay_no: string;
    /* out_truck_sn: number;
    in_truck_sn: number; */
    lease_sn: number;
    /* @IsNotEmpty({
        message: '计费员不能为空'
    }) */
    fee_nam: string;
    @IsNotEmpty({
        message: '计费时间不能为空'
    })
    fee_tim: Date;
    pay_way_id: string;
    @IsNotEmpty({
        message: '收付款不能为空'
    })
    fee_in_out: string;
    audit_id: string;
    audit_finish_id: string;
    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;
}

export class InitLovDto {
    @IsNotEmpty({
        message: '计费元素不能为空'
    })
    fee_ele: string;
}

export class queryModsByFeeCodDto {
    @IsNotEmpty({
        message: '费目不能为空'
    })
    fee_cod: string;
}

export class queryElesByFeeModDto {
    @IsNotEmpty({
        message: '费目不能为空'
    })
    fee_mod_cod: string;
}
export class ProtocolRatDto {
    @IsString({
        message: '协议代码错误'
    })
    @IsNotEmpty({
        message: '协议代码不能为空'
    })
    @ApiProperty({ description: '协议代码'})
    protocol_cod: string;

    @IsString({
        message: Msgs.FeeCodNamInvalid
    })
    @IsNotEmpty({
        message: Msgs.FeeCodNamEmpty
    })
    @ApiProperty({ description: '费目名称'})
    fee_cod: string;

    @IsString({
        message: '模式错误'
    })
    @IsNotEmpty({
        message: '模式不能为空'
    })
    @ApiProperty({ description: '模式名称'})
    fee_mod: string;

    @IsNumber({}, {
        message: '费率错误'
    })
    @IsNotEmpty({
        message: '费率不能为空'
    })
    @ApiProperty({ description: '费率'})
    fee_rat: number;

    fee_ele1: string;
    fee_ele2: string;
    fee_ele3: string;
    fee_ele4: string;
    fee_ele5: string;
    fee_ele6: string;
    fee_ele7: string;
    fee_ele8: string;
    fee_ele9: string;
    fee_ele10: string;

    @IsString()
    @IsOptional()
    @ApiProperty({ description: '备注'})
    remark?: string;

}
export class FeeAuditDto {
    /* @IsNotEmpty({
        message: '实收付ID不能为空'
    }) */
    pay_id: number;
    /* @IsNotEmpty({
        message: '应收付ID不能为空'
    }) */
    feedet_id: number;
    /* @IsNotEmpty({
        message: '应收付金额不能为空'
    }) */
    pay_amount: number;
    /* @IsNotEmpty({
        message: '应收付金额不能为空'
    }) */
    feedet_amount: number;
    @IsNotEmpty({
        message: '核销时间不能为空'
    })
    audit_tim: Date;

    @IsNotEmpty({
        message: '核销号不能为空'
    })
    audit_no: string;

    /* @IsNotEmpty({
        message: '汇率不能为空'
    }) */
    currency_rate: number;

    @IsEnum(BooleanType, {
        message: '强制核销标识错误'
    })
    @IsNotEmpty({
        message: '强制核销标志不能为空'
    })
    force_flag: BooleanType;



    @IsString()
    @IsOptional()
    remark?: string;
}

export class AuditDto {
    
    @IsNotEmpty({
        message: '客户不能为空'
    })
    fee_unit_cod: number;
    @IsNotEmpty({
        message: '收付款不能为空'
    })
    fee_in_out: FeeInOutType;
    @IsNotEmpty({
        message: '成本中心不能为空'
    })
    fee_owner: number
    force_audit: string;  // 强制核销 'Y'
    audit_remark: string; // 强制核销备注
    @IsArray()
    //@ValidateNested({ each: true }) // 对数组中的每个元素应用验证
    @IsNotEmpty()
    payids: number[];

    @IsArray() // 确保数组中的每个元素都是字符串
    @IsNotEmpty() // 确保数组不为空
    // @Type(() => number) // 使用class-transformer确保类型安全
    feedetids: number[];
}

export class InvoiceDto {

    @IsNotEmpty({
        message: '销售方不能为空'
    })
    from_corp_nam: string;
    @IsNotEmpty({
        message: '购买方不能为空'
    })
    to_corp_nam: string;
    @IsNotEmpty({
        message: '发票号不能为空'
    })
    invoice_no: string;

    /* @IsNotEmpty({
        message: '发票代码不能为空'
    }) */
    invoice_cod: string;
    @IsNotEmpty({
        message: '货币不能为空'
    })
    currency_cod: string;
    /* @IsNotEmpty({
        message: '户头不能为空'
    })
    fee_unit_nam: string; */

    @IsNotEmpty({
        message: '发票日期不能为空'
    })
    invoice_date: Date;

    // tax_no: string;

    @IsNotEmpty({
        message: '非含税价不能为空'
    })
    cost_amount: number;

    tax_rate: number;
    @IsString()
    @IsOptional()
    remark?: string;

    details: InvoiceDetailDto[];
}
export class InvoiceDetailDto {
    @IsNotEmpty({
        message: '发票ID不能为空'
    })
    invoice_id: number;

    cntr_typ: string;
    status: string;
    description: string;
    qty: number;
    price: string;
    amount: number;
    remark: string;
}
class InvoiceAuditDto {
    
    
    invoice_id: number;
    
    
    invoice_amount: number;
    @IsNotEmpty({
        message: '核销时间不能为空'
    })
    audit_tim: Date;

    @IsNotEmpty({
        message: '核销号不能为空'
    })
    audit_no: string;
    
    @IsEnum(BooleanType, {
        message: '强制核销标识错误'
    })
    @IsNotEmpty({
        message: '强制核销标志不能为空'
    })
    force_flag: BooleanType;

    @IsString()
    @IsOptional()
    remark?: string;
}
/**
 * 生成Invoice_audit_pay 时  接口
 */
export class InvoicePayAuditDto extends InvoiceAuditDto {
    
    pay_id: number;
    
    pay_amount: number;
}
export class InvoiceFeedetAuditDto extends InvoiceAuditDto {
    
    feedet_id: number;
    
    feedet_amount: number;
}
class AuditInvoiceDto {
    force_audit: string;  // 强制核销 'Y'
    audit_remark: string; // 强制核销备注
    
    @IsArray()
    //@ValidateNested({ each: true }) // 对数组中的每个元素应用验证
    @IsNotEmpty()
    invoiceIds: number[];
}

/**
 * 前端接口
 */
export class AuditInvoicePayDto extends AuditInvoiceDto {
    @IsArray()
    //@ValidateNested({ each: true }) // 对数组中的每个元素应用验证
    @IsNotEmpty()
    payids: number[];
}

export class AuditInvoiceFeedetDto extends AuditInvoiceDto {
    @IsArray()
    //@ValidateNested({ each: true }) // 对数组中的每个元素应用验证
    @IsNotEmpty()
    feedetids: number[];
}

export class BusinessReportDto {
    
    start_tim: Date;    
    end_tim: Date;

    @IsNotEmpty()
    month: Date;

    fee_owner: number;
    category_id: number;
    // fee_owner: number;
    // fee_typ_cod: string;
}

export class BusiReportDto {
    @IsNotEmpty({
        message: '开始日期不能为空'
    })
    start_tim: Date;

    @IsNotEmpty({
        message: '截止日期不能为空'
    })
    end_tim: Date;

    @IsOptional()
    fee_owner: number;

}
//  报表定义
export class FeeReportDefineDto {
    @IsNotEmpty({
        message: '报表名称不能为空'
    })
    r_name: string;

    @IsNotEmpty({
        message: '收付款类型不能为空'
    })
    fee_in_out: string;

    @IsArray()
    //@ValidateNested({ each: true }) // 对数组中的每个元素应用验证
    @IsNotEmpty()
    fee_cods: string[];

}

export class LeaseFeeReportDto {
    

    @IsNotEmpty({
        message: 'skip参数错误'
    })
    skip: number;

    @IsNotEmpty({
        message: 'take参数错误'
    })
    take: number;

    @IsNotEmpty({
        message: '开始日期不能为空'
    })
    start_tim: Date;

    @IsNotEmpty({
        message: '截止日期不能为空'
    })
    end_tim: Date;

    @IsNotEmpty({
        message: '客户不能为空'
    })
    fee_owner: number;

    
}
export class LeaseReportDto {
    @IsNotEmpty({
        message: 'skip参数错误'
    })
    skip: number;

    @IsNotEmpty({
        message: 'take参数错误'
    })
    take: number;
    @IsNotEmpty({
        message: '开始日期不能为空'
    })
    start_tim: Date;

    @IsNotEmpty({
        message: '截止日期不能为空'
    })
    end_tim: Date;
    fee_owner: number;
}
export class LeaseFeeUsdInvoiceDto {

    @IsNotEmpty({
        message: '开始日期不能为空'
    })
    start_tim: Date;

    @IsNotEmpty({
        message: '截止日期不能为空'
    })
    end_tim: Date;

    @IsNotEmpty({
        message: '客户不能为空'
    })
    fee_owner: number;

    @IsNotEmpty({
        message: '发票号不能为空'
    })
    invoiceNo: string;

    /* @IsNotEmpty({
        message: '开票日期不能为空'
    })
    invoiceDate: Date; */

}